package com.cskaoyan.service;

import com.cskaoyan.Utils.ListLimit;
import com.cskaoyan.domain.*;
import com.cskaoyan.mapper.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
@Transactional
public class HomeIndexImpl implements HomeIndex {
    @Autowired
    MarketAdMapper marketAdMapper;
    @Autowired
    MarketSystemMapper systemMapper;
    @Autowired
    MarketBrandMapper brandMapper;
    @Autowired
    MarketCategoryMapper marketCategoryMapper;
    @Autowired
    MarketCouponMapper marketCouponMapper;
    @Autowired
    MarketGoodsMapper marketGoodsMapper;
    @Autowired
    MarketTopicMapper marketTopicMapper;

    @Override
    public Map<String, Object> getIndex() {
        Map<String, Object> map = new HashMap<>();
        //获取banner
        List<MarketAd> bannerList = marketAdMapper.selectByExample(new MarketAdExample());
        map.put("banner", bannerList);
        //获取brandList
        String keyValue1 = systemMapper.selectKeyNameAndKeyValue("market_wx_index_brand");
        MarketBrandExample marketBrandExample = new MarketBrandExample();
        marketBrandExample.setOrderByClause("add_time");
        List<MarketBrand> brandList = brandMapper.selectByExample(marketBrandExample);
        List<MarketBrand> realBrandList = brandList.stream().limit(Integer.parseInt(keyValue1)).collect(Collectors.toList());
        map.put("brandList", realBrandList);
        //获取channel
        String keyValue2 = systemMapper.selectKeyNameAndKeyValue("market_wx_catlog_list");
        MarketCategoryExample marketCategoryExample = new MarketCategoryExample();
        marketCategoryExample.setOrderByClause("add_time");
        List realChannelList=ListLimit.limitList(marketCategoryMapper.selectByExampleSelective(marketCategoryExample),keyValue2);
        map.put("channel", realChannelList);
        //获取couponList
        MarketCouponExample marketCouponExample = new MarketCouponExample();
        marketCouponExample.setOrderByClause("add_time");
        List realCouponList = ListLimit.limitList(marketCouponMapper.selectByExampleSelective(marketCouponExample),"3");
        map.put("couponList",realCouponList);
        //获取hotGoodsList
        String keyValue3 = systemMapper.selectKeyNameAndKeyValue("market_wx_index_hot");
        MarketGoodsExample marketGoodsExample = new MarketGoodsExample();
        MarketGoodsExample.Criteria criteria = marketGoodsExample.createCriteria();
        criteria.andIsHotEqualTo(true);
        List realHotGoodsList =ListLimit.limitList(marketGoodsMapper.selectByExampleSelective(marketGoodsExample),keyValue3);
        map.put("hotGoodsList",realHotGoodsList);
        //获取newGoodsList
        String keyValue4 = systemMapper.selectKeyNameAndKeyValue("market_wx_index_new");
        MarketGoodsExample marketGoodsExample1 = new MarketGoodsExample();
        MarketGoodsExample.Criteria criteria1 = marketGoodsExample.createCriteria();
        criteria1.andIsNewEqualTo(true);
        List realNewGoodsList = ListLimit.limitList(marketGoodsMapper.selectByExampleSelective(marketGoodsExample1),keyValue4);
        map.put("newGoodsList",realNewGoodsList);
        //获取topicList
        String keyValue5 = systemMapper.selectKeyNameAndKeyValue("market_wx_index_topic");
        MarketTopicExample marketTopicExample = new MarketTopicExample();
        marketTopicExample.setOrderByClause("add_time");
        List realTopicList = ListLimit.limitList(marketTopicMapper.selectByExampleSelective(marketTopicExample), keyValue5);
        map.put("topicList",realTopicList);
        //floorGoodsList




        return map;
    }
}
